package com.example.onlinemarket.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import static com.example.onlinemarket.util.ActivityUtil.addActivity;
import static com.example.onlinemarket.util.ActivityUtil.contextActivity;
import static com.example.onlinemarket.util.ActivityUtil.removeActivity;


public class BaseActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //用ActivityUtil统一管理程序中所有Activity
        //创建Activity时添加到ActivityUtil的ArrayList<BaseActivity>数组中
        addActivity(this);
    }

    @Override
    protected void onPostResume() {
        super.onPostResume();
        //当当前Activity拥有焦点时，将contextActivity设为自己
        contextActivity = this;
    }

    @Override
    protected void onPause() {
        super.onPause();
        //当当前Activity失去焦点时，将contextActivity设为null
        contextActivity = null;
    }

    @Override
    protected void onDestroy() {
        //销毁Activity时将Activity从数组中移除
        removeActivity(this);
        super.onDestroy();
    }
}
